﻿using HS.Business.Security;
using HS.Domain.EF;
using HS.Presentation.Web.Extensions;
using HS.Presentation.Web.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace HS.Presentation.Web.Controllers
{
    public class SubcondicionController : Controller
    {
        [HttpGet]
        public JsonResult CreateEntity()
        {
            return Json(new SubcondicionBusiness().CreateEntity(), JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult GetEntityByPK(int? idSubcondicion, bool? rowStatus)
        {
            var objResult = new SubcondicionBusiness().GetEntityByPK(idSubcondicion, rowStatus);

            var model = JsonConvert.SerializeObject(objResult, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
            var modelResult = Json(JsonConvert.DeserializeObject(model, typeof(Subcondicion)));

            return modelResult;
        }

        [HttpPost]
        public JsonResult GetEntities(int? idSubcondicion, bool? rowStatus)
        {
            var objResult = new SubcondicionBusiness().GetEntities(idSubcondicion, rowStatus);

            var model = JsonConvert.SerializeObject(objResult, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
            var modelResult = Json(JsonConvert.DeserializeObject(model, typeof(List<Subcondicion>)));

            return modelResult;
        }

        [HttpPost]
        [ForceModelParse(typeof(Subcondicion))]
        public ActionResult GetDlgWindowOpen(Subcondicion model, string dlgPartial)
        {
            if (model.IdSubcondicion == 0)
            {
                ViewBag.State = "New";
            }
            else
            {
                ViewBag.State = "Edit";
            }

            return PartialView(dlgPartial, model);
        }
    }
}
